package cn.com.huzo.repository.purchase.impl;

import cn.com.huzo.model.entities.purchase.PoLinesEntity;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import cn.com.huzo.repository.purchase.PoLinesRepository;

/**
 * 采购订单明细数据访问对象。
 *
 * @author 吴旭
 */
@Repository("PoLinesRepository")
public class PoLinesRepositoryImpl extends GenericRepositoryImpl<PoLinesEntity, String>
        implements PoLinesRepository {

    private final String namespace = "cn.com.huzo.repository.purchase.PoLinesRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public PoLinesRepositoryImpl() {
        super(PoLinesEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer fetchForCount(Map<String, Object> criterion) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForCount"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<PoLinesEntity> fetchForPage(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForPage"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer fetchForCountByPoNo(Map<String, Object> criterion) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForCountByPoNo"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<PoLinesEntity> fetchForPageByPoNo(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForPageByPoNo"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<PoLinesEntity> fetchPoMaterialList(Long headerId) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchPoMaterialList"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<String> fetchAllSelectedLines(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchAllSelectedLines"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insertByImportedMrpLines(Long headerId, Long updatedBy,
            List<String> mrpLinesKeyList, Short separateFlagByPartOfNeed) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("MrpLinesIdList", mrpLinesKeyList);
        criterion.put("SeparateFlagByPartOfNeed", separateFlagByPartOfNeed);
        criterion.put("CreatedBy", updatedBy);
        criterion.put("UpdatedBy", updatedBy);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insertByImportedMrpLines"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insertByImportedMrpFeedingLines(Long headerId, Long updatedBy,
            List<String> mrpFeedingLinesKeyList,
            Short separateFlagByPartOfNeed) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("MrpFeedingLinesIdList", mrpFeedingLinesKeyList);
        criterion.put("SeparateFlagByPartOfNeed", separateFlagByPartOfNeed);
        criterion.put("CreatedBy", updatedBy);
        criterion.put("UpdatedBy", updatedBy);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insertByImportedMrpFeedingLines"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchUpdate(List<PoLinesEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchUpdate"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateRowMaterial(List<PoLinesEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateRowMaterial"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer syncUpdateMainBomLinesMaterial(List<PoLinesEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "syncUpdateMainBomLinesMaterial"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer syncUpdateMrpLinesMaterialSpecification(List<PoLinesEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "syncUpdateMrpLinesMaterialSpecification"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(String key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchDelete(List<PoLinesEntity> itemList) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchDelete"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete_for_sync_lines(Long headerId) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete_for_sync_lines"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<PoLinesEntity> fetchLinesWithOutSubTotal(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchLinesWithOutSubTotal"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<PoLinesEntity> fetchLinesWithSubTotal(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchLinesWithSubTotal"), criterion);
    }
}
